

#import "ASGSearchBar.h"


@implementation ASGSearchBar

- (instancetype )initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.translucent  = YES;
        self.placeholder  = @"输入您感兴趣的岗位";
        self.barTintColor = [UIColor whiteColor];
        self.keyboardType = UIKeyboardTypeDefault;
        self.searchBarStyle =UISearchBarStyleMinimal;
        self.showsCancelButton = NO;
        
        // 找到searchbar的searchField属性
        UITextField *searchField = [self valueForKey:@"searchField"];
        if (searchField) {
            // 背景色
            [searchField setBackgroundColor:[UIColor grayColor]];
            [searchField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
            [searchField setValue:[UIFont boldSystemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];
            
            // 圆角
            searchField.layer.cornerRadius = 10.0f;
            searchField.layer.masksToBounds = YES;
        }
        [self setImage:[UIImage imageNamed:@"hp_search"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
    }
    return self;
}

- (CGSize)intrinsicContentSize {
    // MARK: -  修改了----
    if (@available(iOS 11.0, *)) {
        return UILayoutFittingCompressedSize;
    }
    return CGSizeZero;
}


//- (void)setTfBgColor:(UIColor *)tfBgColor{
//    UITextField *searchField = [self valueForKey:@"searchField"];
//    if (searchField) {
//        // 背景色
//        [searchField setBackgroundColor:[UIColor whiteColor]];
//        [searchField setValue:tfBgColor forKeyPath:@"_placeholderLabel.textColor"];
//    }
//    self.barTintColor = tfBgColor;
//}

@end
